{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "from pandas import set_option\n",
    "set_option(\"display.max_rows\", 15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 设定TXT文件位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# data_path = 'data/NewDataUnProcess/data0417/训练井/'\n",
    "data_path = 'data/NewDataUnProcess/大庆页岩油曲线预测/'\n",
    "# filename 取值例如：'吉404元素测井.txt','吉404常规.txt'， 吉10025录井.txt  'TT1元素测井.txt' 'TT1元素录井.txt'\n",
    "filename = '朝21.txt'\n",
    "# filename = 'BZ102.txt'\n",
    "txt_logs_file = os.path.join(data_path,filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 判定是否是元素测井，是那么为True，不是，为False\n",
    "use_element_names = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "log_data_begin_row = 0\n",
    "a_L = filename.split(\".\")[0][-2:]\n",
    "if a_L == '录井':\n",
    "    log_data_begin_row = 0\n",
    "    print(\"1\")\n",
    "elif a_L == '常规':\n",
    "    log_data_begin_row = 6\n",
    "    print(\"2\")\n",
    "else:\n",
    "    print(\"3\")\n",
    "    log_data_begin_row = 6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# object_name = filename.split(\".\")[0]\n",
    "# file_type_list = [\"录井\",\"常规\"] \n",
    "# for item in file_type_list:    \n",
    "#     str_flag = object_name.find(item)\n",
    "#     if str_flag == \"0\":\n",
    "#         log_data_begin_row = 0\n",
    "#         print(log_data_begin_row)    \n",
    "#     elif str_flag == \"1\":\n",
    "#         log_data_begin_row = 6\n",
    "#         print(log_data_begin_row)\n",
    "#     else:\n",
    "#         log_data_begin_row = 6\n",
    "#         print(log_data_begin_row)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# un_process = pd.read_csv(txt_logs_file,engine='python',encoding='GBK',header = None, sep = '\\000\\r\\t\\n\\tab ')\n",
    "# default log_data_begin_row = 6\n",
    "un_process = pd.read_csv(txt_logs_file,engine='python',encoding='GBK',header = log_data_begin_row, sep = '\\t\\000')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "usual_log_names = [\"DT\",\"CNL\",\"DEN\",\"GR\",\"RD\",\"RS\",\"DTXX\"]\n",
    "element_names = [\"Al\",\"Ca\",\"Fe\",\"K\",\"Mg\",\"Na\",\"S\",\"Si\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 4825 entries, 0 to 4824\n",
      "Data columns (total 1 columns):\n",
      "#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN    4825 non-null object\n",
      "dtypes: object(1)\n",
      "memory usage: 37.8+ KB\n"
     ]
    }
   ],
   "source": [
    "un_process.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1260.0000    32.6160      95.9426      205.489...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1260.1250    33.0750      96.3949      210.850...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1260.2500    33.7480      99.9146      215.119...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1260.3750    33.7460      104.0683     220.570...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1260.5000    32.8600      106.7961     224.781...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4820</th>\n",
       "      <td>1862.5000    25.4460      82.3252      156.988...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4821</th>\n",
       "      <td>1862.6250    26.8410      82.6679      156.518...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4822</th>\n",
       "      <td>1862.7500    27.3550      82.9336      154.851...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4823</th>\n",
       "      <td>1862.8750    27.3640      82.6829      155.279...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4824</th>\n",
       "      <td>1863.0000    27.4080      81.0560      151.015...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4825 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     #DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN\n",
       "0     1260.0000    32.6160      95.9426      205.489...                                             \n",
       "1     1260.1250    33.0750      96.3949      210.850...                                             \n",
       "2     1260.2500    33.7480      99.9146      215.119...                                             \n",
       "3     1260.3750    33.7460      104.0683     220.570...                                             \n",
       "4     1260.5000    32.8600      106.7961     224.781...                                             \n",
       "...                                                 ...                                             \n",
       "4820  1862.5000    25.4460      82.3252      156.988...                                             \n",
       "4821  1862.6250    26.8410      82.6679      156.518...                                             \n",
       "4822  1862.7500    27.3550      82.9336      154.851...                                             \n",
       "4823  1862.8750    27.3640      82.6829      155.279...                                             \n",
       "4824  1863.0000    27.4080      81.0560      151.015...                                             \n",
       "\n",
       "[4825 rows x 1 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# a = un_process.iloc[7].strip('\\t').tolist()\n",
    "un_process"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# default False | True,根据给定的数据分布，一般i情况下不减少原始分辨率\n",
    "use_custom_resolution = False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "if use_element_names == True:\n",
    "    traget_log_names = element_names\n",
    "else:\n",
    "    traget_log_names = usual_log_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "if use_custom_resolution:\n",
    "    custom_resolution = 0.5\n",
    "else:\n",
    "    custom_resolution = 1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 去除末尾缺失值列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "process = un_process.dropna(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1260.0000    32.6160      95.9426      205.489...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1260.1250    33.0750      96.3949      210.850...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1260.2500    33.7480      99.9146      215.119...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1260.3750    33.7460      104.0683     220.570...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1260.5000    32.8600      106.7961     224.781...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4820</th>\n",
       "      <td>1862.5000    25.4460      82.3252      156.988...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4821</th>\n",
       "      <td>1862.6250    26.8410      82.6679      156.518...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4822</th>\n",
       "      <td>1862.7500    27.3550      82.9336      154.851...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4823</th>\n",
       "      <td>1862.8750    27.3640      82.6829      155.279...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4824</th>\n",
       "      <td>1863.0000    27.4080      81.0560      151.015...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4825 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     #DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN\n",
       "0     1260.0000    32.6160      95.9426      205.489...                                             \n",
       "1     1260.1250    33.0750      96.3949      210.850...                                             \n",
       "2     1260.2500    33.7480      99.9146      215.119...                                             \n",
       "3     1260.3750    33.7460      104.0683     220.570...                                             \n",
       "4     1260.5000    32.8600      106.7961     224.781...                                             \n",
       "...                                                 ...                                             \n",
       "4820  1862.5000    25.4460      82.3252      156.988...                                             \n",
       "4821  1862.6250    26.8410      82.6679      156.518...                                             \n",
       "4822  1862.7500    27.3550      82.9336      154.851...                                             \n",
       "4823  1862.8750    27.3640      82.6829      155.279...                                             \n",
       "4824  1863.0000    27.4080      81.0560      151.015...                                             \n",
       "\n",
       "[4825 rows x 1 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 重新制作列名称"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "process_cols = process.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 设定曲线同义词\n",
    "synonyms_names = {'CNC':'CNL','TNPH':'CNL','NPHI':'CNL', \n",
    "                  'KTH_P':'GR', 'HSGR':'GR',\n",
    "                  'RHOB':'DEN','RHO1':'DEN','ZDEN':'DEN','RHOZ':'DEN',\n",
    "                  #'DT':'AC',\n",
    "                 'DTC':'DT',\n",
    "                 'RT':'RD','AT90':'RD','RLA5':'RD','LLD':'RD',\n",
    "                 'RXO':'RS','RLA2':'RS','AT20':'RS','LLS':'RS'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "syn_names = list(synonyms_names.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN']\n"
     ]
    }
   ],
   "source": [
    "# process_cols[0].split(\"W\")[0]\n",
    "if use_element_names == True:\n",
    "    if a_L == '录井':\n",
    "        print('1')\n",
    "        print('process_cols_lenth:',len(process_cols))\n",
    "        print('process_cols:',process_cols)\n",
    "        print(process_cols[1].split('（%')[0].replace(\" \", \"\"))\n",
    "    else:\n",
    "        print(len(process_cols),process_cols,process_cols[1].split(\"DW\")[-1].replace(\" \", \"\"))\n",
    "else:\n",
    "    print(process_cols)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['#DEPTH', 'CNC', 'DTC', 'DTXX', 'GR', 'RD', 'RS', 'ZDEN']\n",
      "1\n",
      "['CNL', 'DT', 'DTXX', 'GR', 'RD', 'RS', 'DEN']\n"
     ]
    }
   ],
   "source": [
    "# 把第一个字母转化为大写字母，其余小写\n",
    "cols = []\n",
    "if use_element_names == True:\n",
    "    if a_L == '录井':\n",
    "        for i in range(1,len(process_cols)):\n",
    "            # a = process_cols[i].split(\" \")[0].strip(\"(%)\").capitalize()\n",
    "            a = process_cols[i].split('（')[0].replace(\" \", \"\").capitalize()\n",
    "            cols.append(a)\n",
    "    else:\n",
    "        for i in range(1,len(process_cols)):\n",
    "            # a = process_cols[i].split(\"_\")[0][2:].capitalize()\n",
    "            a = \"\".join(process_cols[i].split(\"DW\")[-1]).replace(\" \", \"\").capitalize()\n",
    "            #print(a)\n",
    "            cols.append(a)\n",
    "else:\n",
    "    if len(process_cols) == 1:\n",
    "        print(str(process_cols[0]).split())\n",
    "        print(1)\n",
    "        a_list = str(process_cols[0]).split()\n",
    "        for i in range(1,len(a_list)):\n",
    "            a = a_list[i].replace(\" \", \"\")\n",
    "            cols.append(a)\n",
    "        # print(type(a))\n",
    "    else:\n",
    "        for i in range(1,len(process_cols)):\n",
    "            a = process_cols[i].split(\" \")[0]\n",
    "            cols.append(a)\n",
    "    \n",
    "    # 普通测井曲线时候，要注意同义词的替换\n",
    "    for i in range(len(cols)):\n",
    "        if cols[i] in syn_names:\n",
    "            cols[i] = synonyms_names[cols[i]]\n",
    "\n",
    "print(cols)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 判断曲线新列名是否与目标一致"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['DT', 'CNL', 'DEN', 'GR', 'RD', 'RS', 'DTXX']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "traget_log_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "corresponding!!!\n"
     ]
    }
   ],
   "source": [
    "if set(traget_log_names).issubset(set(cols)):\n",
    "    print(\"corresponding!!!\")\n",
    "else:\n",
    "    print(\"logs columns is incompatible!!!\")\n",
    "    missing_logs = [i for i in traget_log_names if (i not in cols)]\n",
    "    print('missing_logs:',missing_logs)\n",
    "#     exit()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 新列名替代原来的列名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(pandas.core.frame.DataFrame,\n",
       " '#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN',\n",
       " ['#DEPTH       CNC          DTC          DTXX         GR           RD           RS           ZDEN'])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(process[process_cols]),str(process_cols[0]),process_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据分列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "if len(process_cols) == 1:\n",
    "    process_new = process[str(process_cols[0])].str.split(expand = True)\n",
    "else:\n",
    "    process_new = process.copy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=8, step=1)"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_new.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "cols.insert(0,\"DEPTH\")\n",
    "process_new.columns = cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>CNL</th>\n",
       "      <th>DT</th>\n",
       "      <th>DTXX</th>\n",
       "      <th>GR</th>\n",
       "      <th>RD</th>\n",
       "      <th>RS</th>\n",
       "      <th>DEN</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1260.0000</td>\n",
       "      <td>32.6160</td>\n",
       "      <td>95.9426</td>\n",
       "      <td>205.4899</td>\n",
       "      <td>117.3900</td>\n",
       "      <td>2.8950</td>\n",
       "      <td>2.9270</td>\n",
       "      <td>2.2810</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1260.1250</td>\n",
       "      <td>33.0750</td>\n",
       "      <td>96.3949</td>\n",
       "      <td>210.8506</td>\n",
       "      <td>116.1980</td>\n",
       "      <td>2.9590</td>\n",
       "      <td>3.0030</td>\n",
       "      <td>2.2190</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1260.2500</td>\n",
       "      <td>33.7480</td>\n",
       "      <td>99.9146</td>\n",
       "      <td>215.1197</td>\n",
       "      <td>118.0710</td>\n",
       "      <td>2.9330</td>\n",
       "      <td>2.9870</td>\n",
       "      <td>2.1840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1260.3750</td>\n",
       "      <td>33.7460</td>\n",
       "      <td>104.0683</td>\n",
       "      <td>220.5702</td>\n",
       "      <td>121.9090</td>\n",
       "      <td>2.8160</td>\n",
       "      <td>2.8850</td>\n",
       "      <td>2.1800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1260.5000</td>\n",
       "      <td>32.8600</td>\n",
       "      <td>106.7961</td>\n",
       "      <td>224.7819</td>\n",
       "      <td>125.9950</td>\n",
       "      <td>2.6510</td>\n",
       "      <td>2.7330</td>\n",
       "      <td>2.1950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4820</th>\n",
       "      <td>1862.5000</td>\n",
       "      <td>25.4460</td>\n",
       "      <td>82.3252</td>\n",
       "      <td>156.9886</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>6.9180</td>\n",
       "      <td>6.7220</td>\n",
       "      <td>2.5610</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4821</th>\n",
       "      <td>1862.6250</td>\n",
       "      <td>26.8410</td>\n",
       "      <td>82.6679</td>\n",
       "      <td>156.5188</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>6.3810</td>\n",
       "      <td>6.2290</td>\n",
       "      <td>2.5660</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4822</th>\n",
       "      <td>1862.7500</td>\n",
       "      <td>27.3550</td>\n",
       "      <td>82.9336</td>\n",
       "      <td>154.8512</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>5.9230</td>\n",
       "      <td>5.7960</td>\n",
       "      <td>2.5700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4823</th>\n",
       "      <td>1862.8750</td>\n",
       "      <td>27.3640</td>\n",
       "      <td>82.6829</td>\n",
       "      <td>155.2792</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>5.6240</td>\n",
       "      <td>5.4930</td>\n",
       "      <td>2.5730</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4824</th>\n",
       "      <td>1863.0000</td>\n",
       "      <td>27.4080</td>\n",
       "      <td>81.0560</td>\n",
       "      <td>151.0156</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>5.5170</td>\n",
       "      <td>5.3660</td>\n",
       "      <td>2.5790</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4825 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH      CNL        DT      DTXX           GR      RD      RS  \\\n",
       "0     1260.0000  32.6160   95.9426  205.4899     117.3900  2.8950  2.9270   \n",
       "1     1260.1250  33.0750   96.3949  210.8506     116.1980  2.9590  3.0030   \n",
       "2     1260.2500  33.7480   99.9146  215.1197     118.0710  2.9330  2.9870   \n",
       "3     1260.3750  33.7460  104.0683  220.5702     121.9090  2.8160  2.8850   \n",
       "4     1260.5000  32.8600  106.7961  224.7819     125.9950  2.6510  2.7330   \n",
       "...         ...      ...       ...       ...          ...     ...     ...   \n",
       "4820  1862.5000  25.4460   82.3252  156.9886  -99999.0000  6.9180  6.7220   \n",
       "4821  1862.6250  26.8410   82.6679  156.5188  -99999.0000  6.3810  6.2290   \n",
       "4822  1862.7500  27.3550   82.9336  154.8512  -99999.0000  5.9230  5.7960   \n",
       "4823  1862.8750  27.3640   82.6829  155.2792  -99999.0000  5.6240  5.4930   \n",
       "4824  1863.0000  27.4080   81.0560  151.0156  -99999.0000  5.5170  5.3660   \n",
       "\n",
       "         DEN  \n",
       "0     2.2810  \n",
       "1     2.2190  \n",
       "2     2.1840  \n",
       "3     2.1800  \n",
       "4     2.1950  \n",
       "...      ...  \n",
       "4820  2.5610  \n",
       "4821  2.5660  \n",
       "4822  2.5700  \n",
       "4823  2.5730  \n",
       "4824  2.5790  \n",
       "\n",
       "[4825 rows x 8 columns]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "process_new"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "new_columns = traget_log_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['DT', 'CNL', 'DEN', 'GR', 'RD', 'RS', 'DTXX']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['DEPTH', 'DT', 'CNL', 'DEN', 'GR', 'RD', 'RS', 'DTXX']"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# C_element.to_csv(data_path + csvfile_name + '_new_'+  '.csv',mode='w',index = False,header=True)\n",
    "new_columns.insert(0,\"DEPTH\")\n",
    "new_columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "log_data = process_new.loc[:,new_columns]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DEPTH</th>\n",
       "      <th>DT</th>\n",
       "      <th>CNL</th>\n",
       "      <th>DEN</th>\n",
       "      <th>GR</th>\n",
       "      <th>RD</th>\n",
       "      <th>RS</th>\n",
       "      <th>DTXX</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1260.0000</td>\n",
       "      <td>95.9426</td>\n",
       "      <td>32.6160</td>\n",
       "      <td>2.2810</td>\n",
       "      <td>117.3900</td>\n",
       "      <td>2.8950</td>\n",
       "      <td>2.9270</td>\n",
       "      <td>205.4899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1260.1250</td>\n",
       "      <td>96.3949</td>\n",
       "      <td>33.0750</td>\n",
       "      <td>2.2190</td>\n",
       "      <td>116.1980</td>\n",
       "      <td>2.9590</td>\n",
       "      <td>3.0030</td>\n",
       "      <td>210.8506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1260.2500</td>\n",
       "      <td>99.9146</td>\n",
       "      <td>33.7480</td>\n",
       "      <td>2.1840</td>\n",
       "      <td>118.0710</td>\n",
       "      <td>2.9330</td>\n",
       "      <td>2.9870</td>\n",
       "      <td>215.1197</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1260.3750</td>\n",
       "      <td>104.0683</td>\n",
       "      <td>33.7460</td>\n",
       "      <td>2.1800</td>\n",
       "      <td>121.9090</td>\n",
       "      <td>2.8160</td>\n",
       "      <td>2.8850</td>\n",
       "      <td>220.5702</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1260.5000</td>\n",
       "      <td>106.7961</td>\n",
       "      <td>32.8600</td>\n",
       "      <td>2.1950</td>\n",
       "      <td>125.9950</td>\n",
       "      <td>2.6510</td>\n",
       "      <td>2.7330</td>\n",
       "      <td>224.7819</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4820</th>\n",
       "      <td>1862.5000</td>\n",
       "      <td>82.3252</td>\n",
       "      <td>25.4460</td>\n",
       "      <td>2.5610</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>6.9180</td>\n",
       "      <td>6.7220</td>\n",
       "      <td>156.9886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4821</th>\n",
       "      <td>1862.6250</td>\n",
       "      <td>82.6679</td>\n",
       "      <td>26.8410</td>\n",
       "      <td>2.5660</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>6.3810</td>\n",
       "      <td>6.2290</td>\n",
       "      <td>156.5188</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4822</th>\n",
       "      <td>1862.7500</td>\n",
       "      <td>82.9336</td>\n",
       "      <td>27.3550</td>\n",
       "      <td>2.5700</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>5.9230</td>\n",
       "      <td>5.7960</td>\n",
       "      <td>154.8512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4823</th>\n",
       "      <td>1862.8750</td>\n",
       "      <td>82.6829</td>\n",
       "      <td>27.3640</td>\n",
       "      <td>2.5730</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>5.6240</td>\n",
       "      <td>5.4930</td>\n",
       "      <td>155.2792</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4824</th>\n",
       "      <td>1863.0000</td>\n",
       "      <td>81.0560</td>\n",
       "      <td>27.4080</td>\n",
       "      <td>2.5790</td>\n",
       "      <td>-99999.0000</td>\n",
       "      <td>5.5170</td>\n",
       "      <td>5.3660</td>\n",
       "      <td>151.0156</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4825 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          DEPTH        DT      CNL     DEN           GR      RD      RS  \\\n",
       "0     1260.0000   95.9426  32.6160  2.2810     117.3900  2.8950  2.9270   \n",
       "1     1260.1250   96.3949  33.0750  2.2190     116.1980  2.9590  3.0030   \n",
       "2     1260.2500   99.9146  33.7480  2.1840     118.0710  2.9330  2.9870   \n",
       "3     1260.3750  104.0683  33.7460  2.1800     121.9090  2.8160  2.8850   \n",
       "4     1260.5000  106.7961  32.8600  2.1950     125.9950  2.6510  2.7330   \n",
       "...         ...       ...      ...     ...          ...     ...     ...   \n",
       "4820  1862.5000   82.3252  25.4460  2.5610  -99999.0000  6.9180  6.7220   \n",
       "4821  1862.6250   82.6679  26.8410  2.5660  -99999.0000  6.3810  6.2290   \n",
       "4822  1862.7500   82.9336  27.3550  2.5700  -99999.0000  5.9230  5.7960   \n",
       "4823  1862.8750   82.6829  27.3640  2.5730  -99999.0000  5.6240  5.4930   \n",
       "4824  1863.0000   81.0560  27.4080  2.5790  -99999.0000  5.5170  5.3660   \n",
       "\n",
       "          DTXX  \n",
       "0     205.4899  \n",
       "1     210.8506  \n",
       "2     215.1197  \n",
       "3     220.5702  \n",
       "4     224.7819  \n",
       "...        ...  \n",
       "4820  156.9886  \n",
       "4821  156.5188  \n",
       "4822  154.8512  \n",
       "4823  155.2792  \n",
       "4824  151.0156  \n",
       "\n",
       "[4825 rows x 8 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 获取测井日志属性信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "if  a_L == '录井':\n",
    "    well_name = filename.split(\"录井\")[0]\n",
    "    orgin_resolution = custom_resolution\n",
    "else:\n",
    "    well_log_info = pd.read_csv(txt_logs_file,engine='python',encoding='GBK',header = None, \n",
    "                                sep = '\\t', nrows = 7)\n",
    "    well_name = well_log_info.iloc[0].to_string().split()[-1]\n",
    "    orgin_resolution = well_log_info.iloc[3].to_string().split()[-1]\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'朝21井'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# well_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "if use_element_names == True:\n",
    "    save_data_path = 'data/elements_logs/'\n",
    "else:\n",
    "    save_data_path =  'data/usual_logs/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "log_data.to_csv(save_data_path + well_name + '_R_' + str(orgin_resolution) + 'm.csv',mode='w',index = False,header=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finished!!\n"
     ]
    }
   ],
   "source": [
    "print(\"Finished!!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data/usual_logs/朝21井_R_ 0.1250       m.csv\n"
     ]
    }
   ],
   "source": [
    "print(save_data_path + well_name + '_R_' + str(orgin_resolution) + 'm.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "256px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
